<template>
  <div>
    <el-scrollbar v-if="direction == 'vertical'" class="box-vertical">
      <div id="print" class="print vertical" :style="{ backgroundImage: 'url(' + backgroundUrl + ')' }">
        <div class="print-img" />
        <div class="print-title">{{ cert.cert_info.title || '学时证明' }}</div>
        <div class="print-info" v-html="cert.cert_info.content" />
        <div v-if="cert.cert_info.show_sections == 1" class="print-section">
          <div v-for="(item, index) in cert.course_list" :key="index" class="item">{{ item.title }}</div>
        </div>
        <el-image v-if="cert.cert_info.official_seal_place == 'right-top'" fit="fill" :src="official_seal_url" class="print-chapter-right-top" />
        <el-image v-if="cert.cert_info.official_seal_place == 'right-bottom'" fit="fill" :src="official_seal_url" class="print-chapter-right-bottom" />
      </div>
    </el-scrollbar>
    <el-scrollbar v-else class="box-horizontal">
      <div id="print" class="print horizontal" :style="{ backgroundImage: 'url(' + backgroundUrl + ')' }">
        <div class="print-img" />
        <div class="print-title">{{ cert.cert_info.title || '学时证明' }}</div>
        <div class="print-info" v-html="cert.cert_info.content" />
        <div v-if="cert.cert_info.show_sections == 1" class="print-section">
          <div v-for="(item, index) in cert.course_list" :key="index" class="item">{{ item.title }}</div>
        </div>
        <el-image v-if="cert.cert_info.official_seal_place == 'right-top'" fit="fill" :src="official_seal_url" class="print-chapter-right-top" />
        <el-image v-if="cert.cert_info.official_seal_place == 'right-bottom'" fit="fill" :src="official_seal_url" class="print-chapter-right-bottom" />
      </div>
    </el-scrollbar>
  </div>
</template>

<script>
export default {
  props: {
    cert: {
      type: Object,
      required: true
    },
    direction: {
      type: String,
      default: 'vertical'
    }
  },
  computed: {
    official_seal_url() {
      return this.cert.cert_info.official_seal_url || '';
    },
    backgroundUrl() {
      return this.cert.cert_info.background_url || require('@/assets/course/cert/print-bg.png');
    }
  }
};
</script>

<style lang="scss">
.el-scrollbar__view {
  height: calc(100vh - 8vh - 176px);
}

.box-horizontal .el-scrollbar__view {
  width: 1120px;
}

.print {
  &.vertical {
    width: 794px;
    min-height: 1123px;
  }
  &.horizontal {
    width: 1123px;
    height: 794px;
  }
  margin: 0 auto;
  padding: 25px 40px 60px;
  box-sizing: border-box;
  // background-image: url('~@/assets/course/cert/print-bg.png');
  position: relative;
  &-img {
    width: 383px;
    height: 26px;
    margin: 0 auto;
    background-image: url('~@/assets/course/cert/print-top.png');
    background-size: 100% 100%;
    background-repeat: no-repeat;
  }
  &-title {
    margin-top: 26px;
    font-size: 26px;
    font-weight: bold;
    color: #b06030;
    text-align: center;
  }
  &-info {
    font-size: 13px;
    color: #454545;
    margin-top: 34px;
  }
  &-section {
    margin-top: 23px;
    border: 1px solid #a0a0a0;
    .item {
      color: #454545;
      font-size: 12px;
      padding: 10px;
      text-align: center;
      & + .item {
        border-top: 1px solid #a0a0a0;
      }
    }
  }
  &-chapter-right-top {
    position: absolute;
    top: 40px;
    right: 30px;
  }
  &-chapter-right-bottom {
    position: absolute;
    bottom: 15px;
    right: 30px;
  }
  .el-image {
    width: 165px;
    height: auto;
  }
}
</style>
